package edu.its.dreamteam.web.pages.admin;

import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.ioc.annotations.Inject;

import edu.its.dreamteam.daf.beans.Club;
import edu.its.dreamteam.daf.dao.IClubDao;
import edu.its.dreamteam.web.base.SecureBasePage;

public class ClubForm extends SecureBasePage{
	@Inject
	private IClubDao clubDao;
	@Persist
	private Club club;
	/*@Component 
	private Form clubForm;
	*/
	private String idClub;
	
	public Club getClub() {
		return club;
	}
	
	public IClubDao getClubDao() {
		return clubDao;
	}
	
	
	void onPrepare(){
        if (club == null){
        	club = new Club();         	
        }        
    }
	
	void cleanupRender() {
		club = null;
	}
	
	void onActionFromClear(){
		club = null;
		//clubForm.clearErrors();
    }	

	Object onSuccessFromClubForm(){
		if(getClub().getIdClub()==null)	{	
			getClubDao().insert(getClub());
			
		}else{			
			getClubDao().update(getClub());
						
		}
		club = null;
		return ClubGrid.class;
	}
	
	void onActivate(String idClub){	
		this.idClub = idClub;
		club = (Club) getClubDao().findByPrimaryKey(idClub);		
	}
	
	String onPassivate(){ 
		return idClub; 
	}	
	
}
